'use strict';
const Service = require('egg').Service;

class OrderService extends Service {
  async getAllRegion() {
    const aData = await this.app.mysql.select('region', {
      where: { type: 1 },
    });
    const bData = await this.app.mysql.select('region', {
      where: { type: 2 },
    });
    const cData = await this.app.mysql.select('region', {
      where: { type: 3 },
    });
    const result = [];
    for (const aItem of aData) {
      const bArr = [];
      for (const bItem of bData) {
        const cArr = [];
        for (const cItem of cData) {
          if (cItem.parent_id === bItem.id) {
            cArr.push({
              value: cItem.id,
              label: cItem.name,
            });
          }
        }
        if (bItem.parent_id === aItem.id) {
          bArr.push({
            value: bItem.id,
            label: bItem.name,
            children: cArr,
          });
        }
      }
      result.push({
        value: aItem.id,
        label: aItem.name,
        children: bArr,
      });
    }
    return {
      code: 0,
      data: result,
    };
  }
}
module.exports = OrderService;
